<style>
    .form .label { width:110px; padding-right:15px; }
</style>
<div class="form" style="overflow: auto">
    <?php
    $form = $this->beginWidget('CActiveForm', array(
	'id' => 'article-_form-form',
	'enableAjaxValidation' => false,
	'enableClientValidation' => false,
	'clientOptions' => array('validateOnSubmit' => true, 'validateOnType' => true)
    ));
    $articleState = Yii::app()->user->getState(app()->controller->id . 'article');
    ?>
    <?php
    if ($model->introtext != '' && strpos($model->fulltext, LGConstant::ARTICLE_READ_MORE_LINE) === false) {
	$model->fulltext = $model->introtext . LGConstant::ARTICLE_READ_MORE_LINE . $model->fulltext;
    }
    ?>

    <input type="hidden" id='lastUpdateDate' name='lastUpdateDate' value='<?php echo $model->update_date ?>' />
    <div>
        <div style="width: 53%; float: left">
            <table >

		<tr>
                    <td class="label required"><?php echo $form->labelEx($model, 'title'); ?></td>
                    <td class="input" >
			<?php echo $form->textField($model, 'title', array('style' => 'width:270px', 'placeholder' => t('PLH_TITLE', 'article'))); ?>
			<?php echo $form->error($model, 'title'); ?>
                    </td>
                </tr>
                <tr>
                    <td class="label required"><?php echo $form->labelEx($model, 'alias'); ?></td>
                    <td class="input" >
			<?php echo $form->textField($model, 'alias', array('style' => 'width:270px', 'placeholder' => t('PLH_ALIAS', 'article'))); ?>
			<?php echo $form->error($model, 'alias'); ?>
                    </td>
                </tr>

                <tr>
                    <td class="label required"><?php echo $form->labelEx($model, 'catid'); ?></td>
                    <td class="input" >
			<?php
//echo $form->dropDownList($model, 'catid', Html::listData(Category::model()->findAll(), 'id', 'name'), array(
//'empty' => Yii::t('messages', 'MSG_FIRST_ITEM_CATEGORY')
//    )
//);
			?>

			<?php
			echo $form->dropDownList($model, 'catid', Category::model()->getListDataForParentDropDownList(), array('style' => 'width:280px', 'empty' => t('MSG_FIRST_CATEGORY', 'messages'),
			    'options' => $articleState['catid'] != null ? array($articleState['catid'] => array('selected' => true)) : array()));
			echo $form->error($model, 'catid');
			?>

                    </td>
                </tr>
                <tr>
                    <td class="label required"><?php echo $form->label($model, 'status'); ?></td>
                    <td class="input" >
			<?php
			echo $form->dropDownList($model, 'status', Html::listData(LGHelpers::getStatusArticle(), 'id', 'name'), array(
			    'style' => 'width:200px'
				)
			);
			?>
			<?php echo $form->error($model, 'status'); ?>
                    </td>
                </tr>
                <tr>
                    <td class="label required"><?php echo $form->label($model, 'language'); ?></td>
                    <td class="input" >
			<?php
			echo $form->dropDownList($model, 'language', Html::listData(Language::model()->findAll(), 'code', 'value'), array(
			    'empty' => array('*' => 'All language'), 'style' => 'width:200px'
				)
			);
			?>
			<?php echo $form->error($model, 'language'); ?>
                    </td>
                </tr>
                <tr>
                    <td class="label required"><?php echo $form->label($model, 'featured'); ?></td>
                    <td class="input" >
			<?php
			echo $form->dropDownList($model, 'featured', Html::listData(LGHelpers::getFeaturedArticle(), 'id', 'name'), array(
			    'style' => 'width:200px'
				)
			);
			?>
			<?php echo $form->error($model, 'featured'); ?>
                    </td>
                </tr>
<!--                <tr>
                    <td class="label required"><?php echo $form->label($model, 'can_comment'); ?></td>
                    <td class="input" >
			<?php
			echo $form->dropDownList($model, 'can_comment', Html::listData(LGHelpers::getCommentOption(), 'id', 'name'), array(
			    'style' => 'width:200px'
				)
			);
			?>
			<?php echo $form->error($model, 'can_comment'); ?>
                    </td>
                </tr>-->
            </table>
        </div>

	<div style="float:right; width: 46%; height: auto;">
	    <fieldset>
		<legend>Metadata Options</legend>
		<table >

		    <tr>
			<td class="label required"><?php echo $form->labelEx($model, 'meta_description'); ?></td>
			<td class="input" >
			    <?php echo $form->textArea($model, 'meta_description', array('style' => 'width:230px', 'placeholder' => t('PLH_METAL_DESCRIPTION', 'article'))); ?>
			    <?php echo $form->error($model, 'meta_description'); ?>
			</td>
		    </tr>
		    <tr>
			<td class="label required"><?php echo $form->labelEx($model, 'meta_keyword'); ?></td>
			<td class="input" >
			    <?php echo $form->textArea($model, 'meta_keyword', array('style' => 'width:230px', 'placeholder' => t('PLH_METAL_KEYWORDS', 'article'))); ?>
			    <?php echo $form->error($model, 'meta_keyword'); ?>
			</td>
		    </tr>
		    <tr>
			<td class="label required"><?php echo $form->labelEx($model, 'robots'); ?></td>
			<td class="input" >
			    <?php
			    echo $form->dropDownList($model, 'robots', Html::listData(LGHelpers::getRobots(), 'id', 'name'), array(
				'empty' => Yii::t('messages', 'MSG_FIRST_ROBOTS')
				    )
			    );
			    ?>
			    <?php echo $form->error($model, 'robots'); ?>
			</td>
		    </tr>
		    <tr>
			<td class="label required"><?php echo $form->labelEx($model, 'author'); ?></td>
			<td class="input" >
			    <?php echo $form->textField($model, 'author', array('style' => 'width:230px', 'placeholder' => t('PLH_AUTHOR', 'article'))); ?>
			    <?php echo $form->error($model, 'author'); ?>
			</td>
		    </tr>

		</table>
	    </fieldset>


	</div>

    </div>
    <!--Editor o duoi -->
    <div style="clear: both;"></div>
    <div style='height: auto; width: 100%; '>
        <span class="label required">
	    <?php echo $form->labelEx($model, 'fulltext'); ?>
	</span>
	<?php echo $form->error($model, 'fulltext'); ?>
	<br/>
	<br/>
	<?php
	$this->widget('application.extensions.TheCKEditor.TheCKEditorWidget', array(
	    'model' => $model,
	    'attribute' => "fulltext",
	    'height' => '350px',
	    'width' => '98.5%',
	    //'resizable' => 'false',
	    'toolbarSet' => 'Full', # EXISTING(!) Toolbar (see: ckeditor.js)
	    'ckeditor' => Yii::app()->basePath . '/../ckeditor/ckeditor.php', # Path to ckeditor.php
	    'ckBasePath' => Yii::app()->baseUrl . '/ckeditor/', # Relative Path to the Editor (from Web-Root)
	    'config' => array('baseHref'=> "http://".$_SERVER['HTTP_HOST'].SITE_URL.'/')
	    ));
	?>        
    </div>    
    <?php $this->endWidget(); ?>
    <?php
    echo CHtml::ajaxButton('Image', url('article/browse'), array('onclick' => '$("#fileDialog").dialog("open");return false;',
	'update' => '#fileDialog',), array('id' => 'showFileDialog'));
    ?>
    <button id="readMore" class="button" onclick='ReadMore()' type="button">Read more</button>
    <div id="fileDialog"></div>    
    <script src="<?php echo Yii::app()->theme->baseUrl; ?>/js/jquery.tooltip.js" type="text/javascript"></script>

     <script type="text/javascript">
	LGCMS.addTooltip();
	function ReadMore() {

	    var data = CKEDITOR.instances['Article[fulltext]'].getData();

		//Have a exception for IE 9
	    if (data.indexOf('<?php echo LGConstant::ARTICLE_READ_MORE_LINE; ?>') == -1
		&& data.indexOf('<?php echo LGConstant::ARTICLE_READ_MORE_LINE_IE9; ?>') == -1) {
		CKEDITOR.instances['Article[fulltext]'].insertElement(CKEDITOR.dom.element.createFromHtml('<?php echo LGConstant::ARTICLE_READ_MORE_LINE; ?>'));
	    }
	    else {
		alert("There is already a 'Read more...' link that has been inserted!");
	    }


	}
    </script>
</div><!-- form -->
